﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_Modes;
using Zor_DAL;
using Zor_Tools;

namespace Zor_Bll
{
    public class Index_Bll<T> where T : class
    {

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="us">登陆用户</param>
        /// <returns></returns>
        public static BaseAnswer UserLogin(string userName,string userPass)
        {
            BaseAnswer bar = new BaseAnswer();
            Sys_Users sysUser = Index_DAL<T>.UserLogin(userName, MD5Helper.StringToMD5(userPass)) as Sys_Users;
            if (sysUser == null)
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "用户名不存在！";
            }
            else if (sysUser.User_Password.Equals(MD5Helper.StringToMD5(userPass)) && sysUser.User_UserName.Equals(userName))
            {
                bar.AnswerType = BaseAnswer.Answers.Succee;
                bar.AnswerMeg = "登陆成功";

                RequestSession.AddSessionUser(sysUser);
            }
            else
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "登陆失败！";
            }
            return bar;
        }

       /// <summary>
       /// 修改密码时，就密码是够输入正确
       /// </summary>
       /// <param name="oldPass"></param>
       /// <returns></returns>
        public static BaseAnswer IsOldPassMapping(string oldPass)
        {
            BaseAnswer bar = new BaseAnswer();
            Sys_Users sysUser = Index_DAL<T>.IsOldPassMapping(MD5Helper.StringToMD5(oldPass)) as Sys_Users;
            if (sysUser == null)
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "旧密码输入不正确！";
            }
            else
            {
                bar.AnswerMeg = "";
            }
            return bar;
        }

        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="newPass"></param>
        /// <returns></returns>
        public static BaseAnswer UpdatePass(string newPass)
        {
            BaseAnswer bar = new BaseAnswer();
            Sys_Users sysUser = Index_DAL<T>.UpdatePass(MD5Helper.StringToMD5(newPass)) as Sys_Users;
            if (sysUser != null)
            {
               
                bar.AnswerMeg = "密码修改失败！";
            }
            else
            {
                bar.AnswerType = BaseAnswer.Answers.Failure;
                bar.AnswerMeg = "密码修改成功！";
            }
            return bar;
        }
    }
}
